<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="API docs for the runZoned function from the dart:async library, for the Dart programming language.">
  <title>runZoned function - dart:async library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">

</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">spritewidget</a></li>
    <li><a href="dart-async/dart-async-library.html">dart:async</a></li>
    <li class="self-crumb">runZoned&lt;<wbr><span class="type-parameter">R</span>&gt; function</li>
  </ol>
  <div class="self-name">runZoned</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <h5>dart:async library</h5>
    <ol>
      <li class="section-title"><a href="dart-async/dart-async-library.html#classes">Classes</a></li>
      <li><a href="dart-async/Completer-class.html">Completer</a></li>
      <li><a class="deprecated" href="dart-async/DeferredLibrary-class.html">DeferredLibrary</a></li>
      <li><a href="dart-async/EventSink-class.html">EventSink</a></li>
      <li><a href="dart-async/Future-class.html">Future</a></li>
      <li><a href="dart-async/FutureOr-class.html">FutureOr</a></li>
      <li><a href="dart-async/Stream-class.html">Stream</a></li>
      <li><a href="dart-async/StreamConsumer-class.html">StreamConsumer</a></li>
      <li><a href="dart-async/StreamController-class.html">StreamController</a></li>
      <li><a href="dart-async/StreamIterator-class.html">StreamIterator</a></li>
      <li><a href="dart-async/StreamSink-class.html">StreamSink</a></li>
      <li><a href="dart-async/StreamSubscription-class.html">StreamSubscription</a></li>
      <li><a href="dart-async/StreamTransformer-class.html">StreamTransformer</a></li>
      <li><a href="dart-async/StreamTransformerBase-class.html">StreamTransformerBase</a></li>
      <li><a href="dart-async/StreamView-class.html">StreamView</a></li>
      <li><a href="dart-async/SynchronousStreamController-class.html">SynchronousStreamController</a></li>
      <li><a href="dart-async/Timer-class.html">Timer</a></li>
      <li><a href="dart-async/Zone-class.html">Zone</a></li>
      <li><a href="dart-async/ZoneDelegate-class.html">ZoneDelegate</a></li>
      <li><a href="dart-async/ZoneSpecification-class.html">ZoneSpecification</a></li>
    
    
    
      <li class="section-title"><a href="dart-async/dart-async-library.html#functions">Functions</a></li>
      <li><a href="dart-async/runZoned.html">runZoned</a></li>
      <li><a href="dart-async/scheduleMicrotask.html">scheduleMicrotask</a></li>
    
    
      <li class="section-title"><a href="dart-async/dart-async-library.html#typedefs">Typedefs</a></li>
      <li><a href="dart-async/ControllerCallback.html">ControllerCallback</a></li>
      <li><a href="dart-async/ControllerCancelCallback.html">ControllerCancelCallback</a></li>
      <li><a href="dart-async/CreatePeriodicTimerHandler.html">CreatePeriodicTimerHandler</a></li>
      <li><a href="dart-async/CreateTimerHandler.html">CreateTimerHandler</a></li>
      <li><a href="dart-async/ErrorCallbackHandler.html">ErrorCallbackHandler</a></li>
      <li><a href="dart-async/ForkHandler.html">ForkHandler</a></li>
      <li><a href="dart-async/HandleUncaughtErrorHandler.html">HandleUncaughtErrorHandler</a></li>
      <li><a href="dart-async/PrintHandler.html">PrintHandler</a></li>
      <li><a href="dart-async/RegisterBinaryCallbackHandler.html">RegisterBinaryCallbackHandler</a></li>
      <li><a href="dart-async/RegisterCallbackHandler.html">RegisterCallbackHandler</a></li>
      <li><a href="dart-async/RegisterUnaryCallbackHandler.html">RegisterUnaryCallbackHandler</a></li>
      <li><a href="dart-async/RunBinaryHandler.html">RunBinaryHandler</a></li>
      <li><a href="dart-async/RunHandler.html">RunHandler</a></li>
      <li><a href="dart-async/RunUnaryHandler.html">RunUnaryHandler</a></li>
      <li><a href="dart-async/ScheduleMicrotaskHandler.html">ScheduleMicrotaskHandler</a></li>
      <li><a href="dart-async/ZoneBinaryCallback.html">ZoneBinaryCallback</a></li>
      <li><a href="dart-async/ZoneCallback.html">ZoneCallback</a></li>
      <li><a href="dart-async/ZoneUnaryCallback.html">ZoneUnaryCallback</a></li>
    
      <li class="section-title"><a href="dart-async/dart-async-library.html#exceptions">Exceptions</a></li>
      <li><a href="dart-async/AsyncError-class.html">AsyncError</a></li>
      <li><a href="dart-async/DeferredLoadException-class.html">DeferredLoadException</a></li>
      <li><a href="dart-async/TimeoutException-class.html">TimeoutException</a></li>
    </ol>
  </div><!--/.sidebar-offcanvas-left-->

  <div class="col-xs-12 col-sm-9 col-md-8 main-content">
    <h1>runZoned&lt;<wbr><span class="type-parameter">R</span>&gt; function</h1>

    <section class="multi-line-signature">
        <span class="returntype">R</span>
        <span class="name ">runZoned</span>
&lt;<wbr><span class="type-parameter">R</span>&gt;(<wbr><span class="parameter" id="runZoned-param-body"><span class="type-annotation">R</span> <span class="parameter-name">body</span>(), {</span> <span class="parameter" id="runZoned-param-zoneValues"><span class="type-annotation"><a href="dart-core/Map-class.html">Map</a></span> <span class="parameter-name">zoneValues</span>, </span> <span class="parameter" id="runZoned-param-zoneSpecification"><span class="type-annotation"><a href="dart-async/ZoneSpecification-class.html">ZoneSpecification</a></span> <span class="parameter-name">zoneSpecification</span>, </span> <span class="parameter" id="runZoned-param-onError"><span class="type-annotation"><a href="dart-core/Function-class.html">Function</a></span> <span class="parameter-name">onError</span></span> })
    </section>
    <section class="desc markdown">
      <p>Runs <code>body</code> in its own zone.</p>
<p>Returns the result of invoking <code>body</code>.</p>
<p>If <code>onError</code> is non-null the zone is considered an error zone. All uncaught
errors, synchronous or asynchronous, in the zone are caught and handled
by the callback. When the error is synchronous, throwing in the <code>onError</code>
handler, leads to a synchronous exception.</p>
<p>Returns <code>null</code> when <code>body</code> threw, and a provided <code>onError</code> function completed
without throwing.</p>
<p>Errors may never cross error-zone boundaries. This is intuitive for leaving
a zone, but it also applies for errors that would enter an error-zone.
Errors that try to cross error-zone boundaries are considered uncaught.</p>
<pre class="language-dart"><code>var future = new Future.value(499);
runZoned(() {
  future = future.then((_) { throw "error in first error-zone"; });
  runZoned(() {
    future = future.catchError((e) { print("Never reached!"); });
  }, onError: (e) { print("unused error handler"); });
}, onError: (e) { print("catches error of first error-zone."); });
</code></pre>
<p>Example:</p>
<pre class="language-dart"><code>runZoned(() {
  new Future(() { throw "asynchronous error"; });
}, onError: print);  // Will print "asynchronous error".
</code></pre>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span> </h2>
      <pre class="language-dart"><code class="language-dart">R runZoned&lt;R&gt;(R body(),
    {Map zoneValues, ZoneSpecification zoneSpecification, Function onError}) {
  &#47;&#47; TODO(floitsch): the return type should be `void` here.
  if (onError != null &amp;&amp;
      onError is! ZoneBinaryCallback&lt;dynamic, Object, StackTrace&gt; &amp;&amp;
      onError is! ZoneUnaryCallback&lt;dynamic, Object&gt;) {
    throw new ArgumentError(&quot;onError callback must take an Object (the error), &quot;
        &quot;or an Object (the error) and a StackTrace&quot;);
  }
  HandleUncaughtErrorHandler errorHandler;
  if (onError != null) {
    errorHandler = (Zone self, ZoneDelegate parent, Zone zone, error,
        StackTrace stackTrace) {
      try {
        if (onError is void Function(Object, StackTrace)) {
          self.parent.runBinary(onError, error, stackTrace);
          return;
        }
        assert(onError is void Function(Object));
        self.parent.runUnary(onError, error);
      } catch (e, s) {
        if (identical(e, error)) {
          parent.handleUncaughtError(zone, error, stackTrace);
        } else {
          parent.handleUncaughtError(zone, e, s);
        }
      }
    };
  }
  if (zoneSpecification == null) {
    zoneSpecification =
        new ZoneSpecification(handleUncaughtError: errorHandler);
  } else if (errorHandler != null) {
    zoneSpecification = new ZoneSpecification.from(zoneSpecification,
        handleUncaughtError: errorHandler);
  }
  Zone zone = Zone.current
      .fork(specification: zoneSpecification, zoneValues: zoneValues);
  if (onError != null) {
    try {
      return zone.run(body);
    } catch (e, stackTrace) {
      if (onError is ZoneBinaryCallback&lt;R, Object, StackTrace&gt;) {
        zone.runBinary(onError, e, stackTrace);
        return null;
      }
      assert(onError is ZoneUnaryCallback&lt;R, Object&gt;);
      zone.runUnary(onError, e);
      return null;
    }
  } else {
    return zone.run(body);
  }
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    spritewidget 0.9.16
  </span>

</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
